<cfparam name="CSAC_Order_ID" type="integer" default="0" />
<cfparam name="Organization_ID" type="integer" default="0" />
<cfparam name="returnUI" type="string" default="orders" />
<cfparam name="passback" type="string" default="" />

<cfscript>
	base = new assets.calgrants.com.Base();
	passbackQueryString = base.passbackToQueryString(passback);
	csacOrderGateway = new assets.calgrants.com.gateway.CSACOrderGateway();
	csacOrder = csacOrderGateway.get(CSAC_Order_ID = CSAC_Order_ID);
	if (csacOrder.getCSAC_Order_ID() eq 0 AND request.authUser.organizationID gt 0) {
		csacOrder.setOrganization_ID(request.authUser.organizationID);
	} else if (Organization_ID gt 0) {
		csacOrder.setOrganization_ID(Organization_ID);
	}
</cfscript>

<cfif csacOrder.getOrganization_ID() eq 0>

	<cfset returnView = view />
	<cfset cancelView = "orders" />
	<cfset passback = "CSAC_Order_ID,0" />
	<cfinclude template="/assets/calgrants/ui/forms/selectOrganization.cfm">

<cfelseif csacOrder.getOrganization_ID() gt 0 and IsNumeric(csacOrder.getCSAC_Order_ID())>

	<cfscript>
		// call CSAC Base to get logic and lists that are kept in CSAC
		csacBase = new assets.csac.com.Base();
		statuses = csacBase.getOrderStatuses();
		// set defaults for new orders
		if (csacOrder.getCSAC_Order_ID() eq 0) {
			csacOrder.setProgram_Year(request.currentProgramYear);
			csacOrder.setStatus(statuses[1].value);
			csacOrder.setOrdered_By_ID(GetAuthUser());
		};
		csacOrders = csacOrderGateway.query(Program_Year = csacOrder.getProgram_Year(), Organization_ID = csacOrder.getOrganization_ID());
		usedWorkshopIDs = ValueList(csacOrders.Workshop_IDs);
		workshopGateway = new assets.calgrants.com.gateway.WorkshopGateway();
		qAllWorkshops = workshopGateway.query(Program_Year = csacOrder.getProgram_Year(), Organization_ID = csacOrder.getOrganization_ID());
		allWorkshopIDs = ValueList(qAllWorkshops.Workshop_ID);
		if (ListLen(usedWorkshopIDs) gt 0) {
			unusedWorkshopIDs = "";
			for (i=1; i lte ListLen(allWorkshopIDs); i++) {
				if (ListFind(usedWorkshopIDs, ListGetAt(allWorkshopIDs, i)) eq 0) {
					unusedWorkshopIDs = ListAppend(unusedWorkshopIDs, ListGetAt(allWorkshopIDs, i));
				}
			}
		} else {
			unusedWorkshopIDs = allWorkshopIDs;	
		}
	</cfscript>
	
	<!--- <cfoutput>
	usedWorkshopIDs: #usedWorkshopIDs#<br />
	allWorkshopIDs: #allWorkshopIDs#<br />
	unusedWorkshopIDs: #unusedWorkshopIDs#<br />
	csacOrder.getCSAC_Order_ID(): #csacOrder.getCSAC_Order_ID()#<br />
	</cfoutput>
	<cfabort> --->
	
	<cfif csacOrder.getCSAC_Order_ID() gt 0 or (csacOrder.getCSAC_Order_ID() eq 0 and ListLen(unusedWorkshopIDs) gt 0)>
	
		<cfscript>
			organizationGateway = new assets.calgrants.com.gateway.OrganizationGateway();
			organization = organizationGateway.get(Organization_ID = csacOrder.getOrganization_ID());
			institutionTypes = csacBase.getInstitutionTypes();
			// call CSAC to get Institutions, High Schools and Cities
			csacGateway = new assets.csac.com.gateway.Gateway();
			institutions = csacGateway.call(objType = "view", obj = "getInstitutions");
			highSchools = csacGateway.call(objType = "view", obj = "getHighSchools");
			cities = csacGateway.call(objType = "view", obj = "getCities");
			if (csacOrder.getCSAC_Order_ID() eq 0) {
				productGateway = new assets.csac.com.gateway.ProductGateway();
				qProducts = productGateway.query(Active = 1, productCategoryIDs = "1,6,7,9,10");
				// prepopulate shipping name, email and phone with the current user
				userGateway = new assets.calgrants.com.gateway.UserGateway();
				orderedBy = userGateway.get(User_ID = GetAuthUser());
				csacOrder.setFirst_Name(orderedBy.getFirst_Name());
				csacOrder.setLast_Name(orderedBy.getLast_Name());
				csacOrder.setEmail(orderedBy.getEmail());
				csacOrder.setPhone(orderedBy.getPhone());
				csacOrder.setExtension(orderedBy.getExtension());
			} else {
				orderProductGateway = new assets.csac.com.gateway.OrderProductGateway();
				qProducts = orderProductGateway.query(Order_ID = csacOrder.getOrder_ID(), Deleted = 0);
			}
		</cfscript>
		
		<cfif csacOrder.getCSAC_Order_ID() eq 0>
			<cfquery name="qWorkshops" dbtype="query">
				select * from qAllWorkshops where Workshop_ID in (#unusedWorkshopIDs#)
			</cfquery>
		<cfelse>
			<cfquery name="qWorkshops" dbtype="query">
				select * from qAllWorkshops where Workshop_ID in (#csacOrder.getWorkshop_IDs()#)
			</cfquery>
		</cfif>
		
		<!--- anticipated students, volunteers, computers, tracking codes --->
		<cfif csacOrder.getCSAC_Order_ID() gt 0>
		<!--- total up anticipated students, volunteers, computers and QoQ for distinct tracking codes --->
			<cfquery name="getWorkshopsStudentVolunteerComputerTotals" dbtype="query">
				select Sum(Anticipated_Students) as totalAnticipatedStudents, Sum(Anticipated_Volunteers) as totalAnticipatedVolunteers, Sum(Anticipated_Computers) as totalAnticipatedComputers from qWorkshops
			</cfquery>
			<cfset totalAnticipatedStudents = getWorkshopsStudentVolunteerComputerTotals.totalAnticipatedStudents />
			<cfset totalAnticipatedVolunteers = getWorkshopsStudentVolunteerComputerTotals.totalAnticipatedVolunteers />
			<cfset totalAnticipatedComputers = getWorkshopsStudentVolunteerComputerTotals.totalAnticipatedComputers />
			<cfquery name="trackingCodes" dbtype="query">
				select Tracking_Code from qProducts where Tracking_Code like '%[_]%' and Deleted = 0
			</cfquery>
		<cfelse>
			<cfset totalAnticipatedStudents = 0 />
			<cfset totalAnticipatedVolunteers = 0 />
			<cfset totalAnticipatedComputers = 0 />
		</cfif>
		
		<script type="text/javascript" language="javascript">
		<!--
			<cfoutput>
				var instituionTypes = #SerializeJSON(institutionTypes)#;
			</cfoutput>

			toggleInstitution = function() {
				var instType = $("#Institution_Type").val();
				//$("#Institution").val("");
				if (instType == "High School") {
					$("#collegeUniversityContainer").hide();
					$("#highSchoolContainer").show();
					$("#institutionContainer").hide();
					$("#departmentContainer").show();
					$("#address1Container").show();
					$("#address2Container").show();
					$("#cityZipCodeContainer").show();
					//$("#zipCodeContainer").show();
				} else if (instType == "College University") {
					$("#collegeUniversityContainer").show();
					$("#highSchoolContainer").hide();
					$("#institutionContainer").hide();
					$("#departmentContainer").show();
					$("#address1Container").show();
					$("#address2Container").show();
					$("#cityZipCodeContainer").show();
					//$("#zipCodeContainer").show();
				} else {
					$("#collegeUniversityContainer").hide();
					$("#highSchoolContainer").hide();
					$("#institutionContainer").show();
					$("#departmentContainer").show();
					$("#address1Container").show();
					$("#address2Container").show();
					$("#cityZipCodeContainer").show();
					//$("#zipCodeContainer").show();
				}
			}
			/*toggleWorkshopEditing = function(workshopId) {
				if ($("#asd_" + workshopId).is(":visible")) {
					$("#asd_" + workshopId).hide();
					$("#avd_" + workshopId).hide();
					$("#acd_" + workshopId).hide();
					$("#asf_" + workshopId).show();
					$("#avf_" + workshopId).show();
					$("#acf_" + workshopId).show();
					$("#web_" + workshopId).text("Done");
				} else {
					$("#asf_" + workshopId).hide();
					$("#avf_" + workshopId).hide();
					$("#acf_" + workshopId).hide();
					$("#asd_" + workshopId).text($("#asf_" + workshopId).val()).show();
					$("#avd_" + workshopId).text($("#avf_" + workshopId).val()).show();
					$("#acd_" + workshopId).text($("#acf_" + workshopId).val()).show();
					$("#web_" + workshopId).text("Change");
				}
			}*/
			adjustWorkshopsStudentVolunteerComputerTotals = function() {
				var anticipatedCheckboxes = $(".workshopCheckbox");
				console.log(anticipatedCheckboxes);
				var asTotal = 0;
				var avTotal = 0;
				var acTotal = 0;
				for (var i=0; i<anticipatedCheckboxes.length; i++) {
					var cb = $("#" + anticipatedCheckboxes[i].id);
					if (cb.is(":checked")) {
						asTotal = asTotal + parseInt($("#asf_" + cb.val()).val());
						avTotal = avTotal + parseInt($("#avf_" + cb.val()).val());
						acTotal = acTotal + parseInt($("#acf_" + cb.val()).val());
					}
				}
				/*
				var isChecked = $("#workshopCheckbox_" + workshopId).is(":checked");
				var asVal = parseInt($("#asf_" + workshopId).val());
				var avVal = parseInt($("#avf_" + workshopId).val());
				var acVal = parseInt($("#acf_" + workshopId).val());
				if (isChecked) {
					totalAnticipatedStudents = totalAnticipatedStudents + asVal;
					totalAnticipatedVolunteers = totalAnticipatedVolunteers + avVal;
					totalAnticipatedComputers = totalAnticipatedComputers + acVal;
				} else {
					totalAnticipatedStudents = totalAnticipatedStudents - asVal;
					totalAnticipatedVolunteers = totalAnticipatedVolunteers - avVal;
					totalAnticipatedComputers = totalAnticipatedComputers - acVal;
				}
				*/
				$("#asTotal").text(asTotal);
				$("#avTotal").text(avTotal);
				$("#acTotal").text(acTotal);
			}				
			validate = function() {
				var error = "";
				var isValid = true;
				var quantities = $(".quantity");
				for (var i=0; i<quantities.length; i++) {
					//var value = quantities[i].value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
					var intRegex = /^\d+$/;
					if(!intRegex.test(quantities[i].value) && isValid) {
						isValid = false;
						error += "All quantites are required.  Enter 0 for none.\n";
					}
				}
				if (!isValid) {
					alert(error);
				} else {
					$("#submitOrderButton").attr("disabled", "disabled");
				}
				return isValid;		
			}
			filePopover = function(productID) {
				console.log(productID);
				$("#filePopover_" + productID).popover({
					placement: "auto left",
					title: "This is the popover title",
					html: "<strong>Woo hoo!</strong><br>This is the html attribute."
				});	
				$("#filePopover_" + productID).popover("show");
			}
			$(function() {
				toggleInstitution();
				/*
				$(".datepicker").datepicker({
					dateFormat: "m/d/y",
					duration: "fast",
					goToCurrent: false,
					showButtonPanel: false,
					currentText: "Current Month",
					closeText: "Close Calendar"
				});
				$("#orderForm").validate({
					// status, first_name, last_name, email, phone, institution_type, address, city, zip_code, quantities
					debug: false,
					rules: {
						Status: {required: true},
						First_Name: {required: true},
						Last_Name: {required: true},
						Email: {required: true, email: true},
						Phone: {required: true, phoneUS: true},
						Institution_Type: {required: true},
						College_University_ID: {
							required: {depends: function(elements) {return $("#Institution_Type").val() == "College University"}}
						},
						High_School_ID: {
							required: {depends: function(elements) {return $("#Institution_Type").val() == "High School"}}
						},
						Institution: {
							required: {depends: function(elements) {return $("#Institution_Type").val() == "Other"}}
						},
						Address1: {required: true},
						City: {required: true},
						Zip_Code: {required: true, digits: true, min: 5}
					},
					messages: {
						Status: "Required",
						First_Name: "Required",
						Last_Name: "Required",
						Email: {
							required: "Required",
							email: "Invalid"
						},
						Phone: {
							required: "Required",
							phoneUS: "Invalid"
						},
						Institution_Type: "Required",
						College_University_ID: "Required",
						High_School_ID: "Required",
						Institution: "Required",
						Address1: "Required",
						City: "Required",
						Zip_Code: {
							required: "Required",
							digits: "Invalid",
							min: "Must be 5 digits"
						}
					},
					focusCleanup: true,
					errorPlacement: function(error, element) {
						$(element).prev("label").children("span").remove();
						error.appendTo(element.prev("label"));
						//$(element).prev("label").children("span");
					},
					errorElement: "span",
					errorClass: "label label-danger",
					validClass: "label label-info",
					highlight: function(element, errorClass, validClass) {
						$(element).prev("label").children("span").removeClass(validClass).addClass(errorClass);
					},
					unhighlight: function(element, errorClass, validClass) {
						$(element).prev("label").children("span").removeClass(errorClass).addClass(validClass);
					}
				});
				*/
				$("#csacOrderModal").modal();
				resizeModal("csacOrderModal");
			})
		//-->
		</script>
		
		<style>
			.col20 {min-width: 20px; width: 20px;}
			.col40 {min-width: 40px; width: 40px;}
			.col80 {min-width: 80px; width: 80px;}
			.col100 {min-width: 100px; width: 100px;}
			.col120 {min-width: 120px; width: 120px;}
			.col100p {width: 100%;}
			a:hover {text-decoration: none;}
		</style>
		
		<cfform id="csacOrderForm" name="csacOrderForm" action="#script_name#" role="form" method="post" onsubmit="return validate();">
			<cfinput type="hidden" name="action" value="saveCSACOrder" />
			<cfinput type="hidden" name="view" value="#returnView#" />
			<cfinput type="hidden" name="CSAC_Order_ID" value="#csacOrder.getCSAC_Order_ID()#" />
			<cfinput type="hidden" name="Order_ID" value="#csacOrder.getOrder_ID()#" />
			
			<div id="csacOrderModal" class="modal modal-fullscreen" data-backdrop="static">
				<div class="modal-header">
					<h3>Order</h3>
				</div>
				<div class="modal-body">
					<div class="container-fluid" style="background-color: white;">
						<div class="row-fluid">
							<div class="span12">
								<h4>Shipping Information</h4>
								<p>Enter the contact information for the person who will receive this order shipment.  Please include any special shipping instructions including holidays when your organization is closed and cannot receive shipments.</p>
							</div>
						</div>
						<cfoutput>
							<div class="row-fluid">
								<div class="span4">
									<!--- <cfif csacOrder.getCSAC_Order_ID() gt 0>
										<div class="clearfix">
											<label>Order ID</label>
											<p class="form-control-static">#csacOrder.getCSAC_Order_ID()#</p>
										</div>
										<div class="clearfix">
											<label>Order Date</label>
											<p class="form-control-static">#DateFormat(csacOrder.getOrder_Date(), "m/d/yyyy")#</p>
										</div>
									</cfif> --->
									<cfif IsUserInRole("Super User")>
										<div class="clearfix">
											<label for="Status" class="required">Status</label>
											<cfselect id="Status" name="Status" class="span12" required="yes" message="Status is required">
												<cfloop index="s" from="1" to="#ArrayLen(statuses)#">
													<option value="#statuses[s].value#"<cfif csacOrder.getStatus() eq statuses[s].value> selected</cfif>>#statuses[s].text#</option>
												</cfloop>
											</cfselect>
										</div>
									<cfelseif csacOrder.getCSAC_Order_ID() gt 0>
										<div class="text-control clearfix">
											<label>Status</label>
											#csacOrder.getStatus()#
										</div>
									</cfif>
									<div class="text-control clearfix">
										<label>Organization</label>
										#organization.getOrganization()#
									</div>
									<div class="clearfix">
										<label for="First_Name" class="required">First Name</label>
										<cfinput type="text" class="span12" id="First_Name" name="First_Name" value="#csacOrder.getFirst_Name()#" required="yes" message="First Name is required">
									</div>
									<div class="clearfix">
										<label for="Last_Name" class="required">Last Name</label>
										<cfinput type="text" class="span12" id="Last_Name" name="Last_Name" value="#csacOrder.getLast_Name()#" required="yes" message="Last Name is required">
									</div>
									<div class="clearfix">
										<label for="Email" class="required">E-mail</label>
										<cfinput type="text" class="span12" id="Email" name="Email" value="#csacOrder.getEmail()#" required="yes" validate="email" message="Email is required and must be a valid e-mail address">
									</div>
									<div class="clearfix">
										<div class="row-fluid">
											<div class="span9">
												<label for="Phone" class="required">Phone</label>
												<cfinput type="text" id="Phone" name="Phone" value="#csacOrder.getPhone()#" class="span12" required="yes" validate="telephone" message="Phone is required and must be a valid phone number" placeholder="######-######-########">
											</div>
											<div class="span3">
												<label for="Extension">Extension</label>
												<cfinput type="text" id="Extension" name="Extension" value="#csacOrder.getExtension()#" class="span12">
											</div>
										</div>
									</div>
								</div>
								<div class="span4">
									<!--- <div class="clearfix">
										<label for="institutionTypes">Institution Type(ahead)</label>
										<input type="text" id="institutionTypes" class="span9" />
									</div> --->
									<div class="clearfix">
										<label for="Institution_Type" class="required">Recipient Type</label>
										<cfselect id="Institution_Type" name="Institution_Type" class="span12" required="yes" message="Institution Type is required" onChange="toggleInstitution();">
											<option value="">Select...</option>
											<cfloop index="t" from="1" to="#ArrayLen(institutionTypes)#">
												<option value="#institutionTypes[t].value#"<cfif csacOrder.getInstitution_Type() eq institutionTypes[t].value> selected</cfif>>#institutionTypes[t].text#</option>
											</cfloop>
										</cfselect>
									</div>
									<div id="collegeUniversityContainer" class="clearfix" style="display: none;">
										<label for="College_University_ID" class="required">College/University</label>
										<cfselect id="College_University_ID" name="College_University_ID" class="span12">
											<option value="">Select...</option>
											<cfloop query="institutions">
												<option value="#Institution_ID#"<cfif csacOrder.getInstitution_ID() eq Institution_ID> selected</cfif>>#Institution# - #FAO_City#</option>
											</cfloop>
										</cfselect>
									</div>
									<div id="highSchoolContainer" class="clearfix" style="display: none;">
										<label for="High_School_ID" class="required">High School</label>
										<cfselect id="High_School_ID" name="High_School_ID" class="span12">
											<option value="">Select...</option>
											<cfloop query="highSchools">
												<option value="#High_School_ID#"<cfif csacOrder.getInstitution_ID() eq High_School_ID> selected</cfif>>#High_School# - #City#</option>
											</cfloop>
										</cfselect>
									</div>
									<div id="institutionContainer" class="clearfix" style="display: none;">
										<label for="Institution" class="required">Institution</label>
										<cfinput type="text" class="span12" id="Institution" name="Institution" value="#csacOrder.getInstitution()#">
									</div>
									<div id="departmentContainer" class="clearfix" style="display: none;">
										<label for="Department">Department</label>
										<cfinput type="text" class="span12" id="Department" name="Department" value="#csacOrder.getDepartment()#">
									</div>
									<div id="address1Container" class="clearfix" style="display: none;">
										<label for="Address" class="required">Address 1</label>
										<cfinput type="text" class="span12" id="Address1" name="Address1" value="#csacOrder.getAddress1()#" required="yes" message="Address 1 is required">
									</div>
									<div id="address2Container" class="clearfix" style="display: none;">
										<label for="Address2">Address 2</label>
										<cfinput type="text" class="span12" id="Address2" name="Address2" value="#csacOrder.getAddress2()#" >
									</div>
									<div id="cityZipCodeContainer" class="clearfix" style="display: none;">
										<div class="row-fluid">
											<div class="span8">
												<label for="City" class="required">City</label>
												<cfinput type="text" id="City" name="City" class="span12" value="#csacOrder.getCity()#" required="yes" message="City is required">
											</div>
											<div class="span4">
												<label for="Zip_Code" class="required">Zip Code</label>
												<cfinput type="text" id="Zip_Code" name="Zip_Code" maxlength="5" class="span12" value="#csacOrder.getZip_Code()#" required="yes" message="Zip Code is required">
											</div>
										</div>
									</div>
								</div>
								<div class="span4">
									<div class="clearfix">
										<label for="Shipping_Instructions">Shipping&nbsp;Instructions</label>
										<cftextarea class="span12" id="Shipping_Instructions" name="Shipping_Instructions" rows="3" placeholder="Include any special instructions and dates your organization is closed. For example...Closed from 12/20 to 1/7">#csacOrder.getShipping_Instructions()#</cftextarea>
									</div>
									<div class="clearfix">
										<label for="Shared_Notes">Notes</label>
										<cftextarea class="span12" id="Shared_Notes" name="Shared_Notes" rows="3">#csacOrder.getShared_Notes()#</cftextarea>
									</div>
									<cfif IsUserInRole("Super User")>
										<div class="clearfix">
											<label for="Private_Notes">Private Notes</label>
											<cftextarea class="span12" id="Private_Notes" name="Private_Notes" rows="3">#csacOrder.getPrivate_Notes()#</cftextarea>
										</div>
									</cfif>
									<cfif csacOrder.getCSAC_Order_ID() gt 0>
										<div class="text-control clearfix">
											<label>Ordered By</label>
											
										</div>
									</cfif>
									<div class="text-control clearfix">
										<label for="Tracking">Tracking Codes</label>
										Tracking codes will appear here when your order is shipped
										<!--- <cfif trackingCodes.RecordCount gt 0>
											<cfloop query="trackingCodes">
												<a href="##" onclick="alert('Integrate with FedEx online tracking'); return false;">#Tracking_Code#</a><br />
											</cfloop>
										<cfelse>
											No tracking codes
										</cfif> --->
									</div>
									<!--- <cfif csacOrder.getCSAC_Order_ID() gt 0>
										<div class="clearfix">
											<label>Approved Date</label>
											<p class="form-control-static">#DateFormat(now(), "m/d/yyyy")#</p>U
										</div>
									</cfif> --->
								</div>
							</div>
						</cfoutput>
						<div class="row-fluid">
							<div class="span12">
								<h4>Workshops</h4>
								<cfif csacOrder.getCSAC_Order_ID() eq 0>
									<p>Choose the workshops that are applicable to this order.  Include all workshops that should be delivered to the shipping address listed above.  For workshops that have a different shipping address create a separate order.</p>
									
									<p> The amounts listed in anticipated students, volunteers and computer were provided at the time of registration.  Please update any amounts if your plans or resources have changed.</p>
								<cfelse>
									<p>The workshops chosen for to this order are listed below.</p>
								</cfif>
								<table class="table table-striped table-bordered">
									<thead>
										<tr>
											<cfif csacOrder.getCSAC_Order_ID() eq 0>
												<th colspan="2">Workshop</th>
											<cfelse>
												<th>Workshop</th>
											</cfif>
											<th>Anticipated Students</th>
											<th>Anticipated Volunteers</th>
											<th>Anticipated Computers</th>
										</tr>
									</thead>
									<tbody>
										<cfoutput query="qWorkshops" group="Site">
											<cfoutput>
												<tr>
													<cfif csacOrder.getCSAC_Order_ID() eq 0>
														<td align="center" style="border-right-width: 0px;"><input type="checkbox" id="workshopCheckbox_#Workshop_ID#" name="Workshop_IDs" value="#Workshop_ID#" class="workshopCheckbox" style="margin: 0; padding: 0;" onclick="adjustWorkshopsStudentVolunteerComputerTotals();"<cfif ListFind(csacOrder.getWorkshop_IDs(), Workshop_ID) gt 0> checked="checked"</cfif>></td>
													</cfif>
													<cfif csacOrder.getCSAC_Order_ID() eq 0> 
														<td class="col100p" style="border-left-width: 0px;">
															#Site#<br />
															#DateFormat(Workshop_Date, "m/d/yyyy")# #TimeFormat(Start_Time, "h:mmtt")#-#TimeFormat(End_Time, "h:mmtt")#
														</td>
													<cfelse>
														<td class="col100p">
															#Site#<br />
															#DateFormat(Workshop_Date, "m/d/yyyy")# #TimeFormat(Start_Time, "h:mmtt")#-#TimeFormat(End_Time, "h:mmtt")#
														</td>
													</cfif>
													<td class="col100">
														<cfif csacOrder.getCSAC_Order_ID() eq 0>
															<input type="text" id="asf_#Workshop_ID#" name="Anticipated_Students_#Workshop_ID#" value="#Anticipated_Students#" class="anticipatedStudentsCount" onchange="adjustWorkshopsStudentVolunteerComputerTotals();" style="width: 80px;" />
														<cfelse>
															#Anticipated_Students#
														</cfif>
													</td>
													<td class="col100">
														<cfif csacOrder.getCSAC_Order_ID() eq 0>
															<input type="text" id="avf_#Workshop_ID#" name="Anticipated_Volunteers_#Workshop_ID#" value="#Anticipated_Volunteers#" class="anticipatedVolunteersCount" onchange="adjustWorkshopsStudentVolunteerComputerTotals();" style="width: 80px;" />
														<cfelse>
															#Anticipated_Volunteers#
														</cfif>
													</td>
													<td class="col100">
														<cfif csacOrder.getCSAC_Order_ID() eq 0>
															<input type="text" id="acf_#Workshop_ID#" name="Anticipated_Computers_#Workshop_ID#" value="#Anticipated_Computers#" class="anticipatedComputersCount" onchange="adjustWorkshopsStudentVolunteerComputerTotals();" style="width: 80px;" />
														<cfelse>
															#Anticipated_Computers#
														</cfif>
													</td>
												</tr>
											</cfoutput>
										</cfoutput>
									</tbody>
									<tfoot>
										<cfoutput>
											<cfif csacOrder.getCSAC_Order_ID() eq 0>
												<th colspan="2" style="text-align: right;">Total</th>
											<cfelse>
												<th style="text-align: right;">Total</th>
											</cfif>
											<th id="asTotal">#totalAnticipatedStudents#</th>
											<th id="avTotal">#totalAnticipatedVolunteers#</th>
											<th id="acTotal">#totalAnticipatedComputers#</th>
										</cfoutput>
									</tfoot>
								</table>
							</div>
						</div>
						<div class="row-fluid">
							<div class="span12">
								<h4>Select Publications</h4>
								<!--- <p>Lorem ipsum...</p> --->
								<cfoutput query="qProducts" group="Category">
									<cfoutput group="Subcategory">
										<h5>#Category#<cfif Len(Subcategory) gt 0> - #Subcategory#</cfif></h5>
										<table class="table table-striped table-bordered">
											<thead>
												<tr>
													<th>Image</th>
													<th>Publication</th>
													<th>File</th>
													<th>Quantity</th>
													<cfif csacOrder.getCSAC_Order_ID() gt 0>
														<th>Quantity Shipped</th>
														<th>Date Shipped</th>
														<th>Tracking Code</th>
													</cfif>
												</tr>
											</thead>
											<tbody>
												<cfoutput>
													<!--- <cfif csacOrder.getCSAC_Order_ID() gt 0 OR (
														Download_Only eq 0 AND (
															(Inventory eq 1 AND (Stock gt 0 OR Allow_Back_Order eq 1)) OR 
															(Inventory eq 0)
														)
													)>
														<cfif csacOrder.getCSAC_Order_ID() eq 0>
															<input type="hidden" name="Order_Product_ID" value="0" />
														<cfelse>
															<input type="hidden" name="Order_Product_ID" value="#Order_Product_ID#" />
														</cfif>
														<input type="hidden" name="Product_ID" value="#Product_ID#" />
													</cfif> --->
													<cfif csacOrder.getCSAC_Order_ID() gt 0>
														<input type="hidden" name="Order_Product_ID" value="#Order_Product_ID#" />
													<cfelse>
														<input type="hidden" name="Order_Product_ID" value="0" />
													</cfif>
													<input type="hidden" name="Product_ID" value="#Product_ID#" />
													<cfset productImages = csacBase.getProductImages(productIDs = Product_ID) />
													<cfset productFiles = csacBase.getProductFiles(productIDs = Product_ID) />
													<tr>
														<td class="col40">
															<cfif productImages.RecordCount gt 0>
																<cfloop query="productImages">
																	<!--- thumbnails should be no more than 60wx50h --->
																	<cfimage action="info" source="#Directory#\#Name#" structname="imageProps">
																	<cfif imageProps.width/imageProps.height gt 60/50>
																		<!--- too wide --->
																		<img src="/csac/common/images/products/#Name#" width="60" />
																	<cfelse>
																		<!--- too tall --->
																		<img src="/csac/common/images/products/#Name#" height="50" />
																	</cfif>
																	<!--- <cfdump var="#imageProps#"> --->
																</cfloop>
															</cfif>
														</td>
														<td>
															#Product#<br />
															<small>#Description#<cfif Len(Trim(Description)) gt 0> </cfif>#ID#</small>
														</td>
														<td class="col80" style="font-size: 2em;">
															<cfif productFiles.RecordCount eq 1>
																<a href="/csac/common/files/products/#productFiles.Name#" target="_blank">1&nbsp;<span class="icon-download-alt"></span></a>
															<cfelseif productFiles.RecordCount gt 1>
																<a href="/csac/common/files/products/#Product_ID#.zip">#productFiles.RecordCount#&nbsp;<span class="icon-download-alt"></span></a>
															<cfelseif Download_Only eq 1>
																<a href="##" onclick="alert('File currently unavailable.\n\nPlease check back.'); return false;">0&nbsp;<span class="icon-download-alt"></span></a>
															</cfif>
														</td>
														<!--- Quantity --->
														<td class="col80">
															<cfif csacOrder.getCSAC_Order_ID() eq 0>
																<cfif Download_Only eq 1>
																	Download only
																<cfelseif Inventory eq 1 and Stock lte 0 and Allow_Back_Order eq 0>
																	Out of stock
																<cfelseif Inventory eq 1 and Stock gt 0 and Allow_Back_Order eq 0>
																	<!--- stock limited --->
																	<cfinput type="text" name="Quantity_#Product_ID#" value="0" required="yes" validate="integer" range="0,#Stock#" message="Quantity for #Product# is required, #Stock# available" class="form-control quantity" style="width: 60px;">
																<cfelseif Inventory eq 0 or Allow_Back_Order eq 1>
																	<!--- unlimited --->
																	<cfinput type="text" name="Quantity_#Product_ID#" value="0" required="yes" validate="integer" range="0," message="Quantity for #Product# is required" class="form-control quantity" style="width: 60px;">
																</cfif>
															<cfelseif csacOrder.getCSAC_Order_ID() gt 0>
																<!--- <input type="hidden" name="Quantity_#Product_ID#" value="#Quantity#" /> --->
																#Quantity#
															</cfif>
														</td>
														<!--- Quantity_Shipped, Date_Shipped, Tracking_Code --->
														<!--- <cfif csacOrder.getCSAC_Order_ID() eq 0 and IsUserLoggedIn()>
															<td nowrap="nowrap">
																<cfif Download_Only eq 1>
																	Download only
																<cfelseif Inventory eq 1 and Stock lte 0 and Allow_Back_Order eq 0>
																	Out of stock
																<cfelseif Inventory eq 1 and Stock gt 0 and Allow_Back_Order eq 0>
																	<!--- stock limited --->
																	<cfinput type="text" name="Quantity_Shipped_#Product_ID#" value="0" required="yes" validate="integer" range="0,#Stock#" message="Quantity Shipped for #Product# is required, #Stock# available" class="form-control quantity" style="width: 100px;">
																<cfelseif Inventory eq 0 or Allow_Back_Order eq 1>
																	<!--- unlimited --->
																	<cfinput type="text" name="Quantity_Shipped_#Product_ID#" value="0" required="yes" validate="integer" range="0," message="Quantity Shipped for #Product# is required" class="form-control quantity" style="width: 100px;">
																</cfif>
															</td> --->
														<cfif csacOrder.getCSAC_Order_ID() gt 0>
															<td class="col80">
																<!--- can be changed up until a Shipped_Date is set --->
																<!--- <cfif IsUserLoggedIn() and NOT IsDate(Shipped_Date)>
																	<cfif Inventory eq 1 and Stock gt 0 and Allow_Back_Order eq 0>
																		<!--- stock limited --->
																		<cfinput type="text" name="Quantity_Shipped_#Product_ID#" value="#Quantity_Shipped#" required="yes" validate="integer" range="0,#Stock#" message="Quantity Shipped for #Product# is required, #Stock# available" class="form-control quantity" style="width: 100px;">
																	<cfelseif Inventory eq 0 or Allow_Back_Order eq 1>
																		<!--- unlimited --->
																		<cfinput type="text" name="Quantity_Shipped_#Product_ID#" value="#Quantity_Shipped#" required="yes" validate="integer" range="0," message="Quantity Shipped for #Product# is required" class="form-control quantity" style="width: 100px;">
																	</cfif>
																<cfelse>
																	<input type="hidden" name="Quantity_Shipped_#Product_ID#" value="#Quantity_Shipped#" /> --->
																	<cfif Quantity_Shipped gt 0>
																		#Quantity_Shipped#
																	</cfif>
																<!--- </cfif> --->					
															</td>
															<td class="col80">
																<!--- <input type="hidden" name="Shipped_Date_#Product_ID#" value="#DateFormat(Shipped_Date, 'm/d/yyyy')#" /> --->
																#DateFormat(Shipped_Date, "m/d/yyyy")#
															</td>
															<td class="col80">#Tracking_Code#</td>
														</cfif>
													</tr>
												</cfoutput>
											</tbody>
										</table>
									</cfoutput>
								</cfoutput>
							</div>
						</div>
					</div>
				</div>
				<div class="modal-footer">
					<cfoutput>
						<a href="?view=#returnView#&#passbackQueryString#" class="btn btn-success">Cancel</a>
						<cfif csacOrder.getCSAC_Order_ID() gt 0 and csacOrder.getStatus() eq "New">
							<a href="?action=deleteCSACOrder&view=#returnView#&CSAC_Order_ID=#csacOrder.getCSAC_Order_ID()#" class="btn btn-success">Delete</a>
						</cfif>
						<button type="submit" name="saveButton" class="btn btn-success">Save</button>
					</cfoutput>
				</div>
			</div>
		</cfform>
		
	<cfelse>
	
		<script type="text/javascript">
			$(function() {
				$("#noWorkshopsModal").modal();
				resizeModal("noWorkshopsModal");	
			})
		</script>
		
		<cfoutput>
			<div id="noWorkshopsModal" class="modal modal-fullscreen" data-backdrop="static">
				<div class="modal-header">
					<h3>No Workshops Available For Order</h3>
				</div>
				<div class="modal-body">
					<div class="container-fluid">
						<div class="row-fluid">
							<div class="span12">
								<p>You must have at least one available workshop to place an order.</p>
<!--- **************************************************************
Alter this so that it shows placed orders with workshops so the user can
understand the case where workshops are registered, but they get this message.
************************************************************** --->
							</div>
						</div>
					</div>
				</div>
				<div class="modal-footer">
					<a href="?view=#returnView#&#passbackQueryString#" class="btn btn-success">Close</a>
				</div>
			</div>
		</cfoutput>
		
	</cfif>
<cfelse>
	<div class="alert alert-info notFound">Order not found</div>
</cfif>
